package licode.unisop.client.feign.impl;

import licode.unisop.client.feign.SoAssetRelVisitFeign;
import licode.unisop.client.visit.AssetRelVisit;
import licode.unisop.client.visit.UniClientTool;
import licode.unisop.client.vo.SopAuthPlatform;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * 定义统一认证平台中心资源相关接口
 *
 * @author licode
 */
@Component
public class AssetRelVisitFeignImpl implements AssetRelVisit {
    @Resource
    private HttpServletRequest request;

    @Resource
    private UniClientTool uniClientTool;

    @Resource
    private SoAssetRelVisitFeign soAssetRelVisitFeign;


    @Override
    public void save(Map<String, Object> req) {
        SopAuthPlatform authPlatform;
        authPlatform = uniClientTool.findAuthPlatform(request, "");
        req.put("realmId", authPlatform.getRealmId());
        soAssetRelVisitFeign.save(authPlatform.getPlatformId(),
                authPlatform.getModelToken(), req);
    }

    @Override
    public void move(Map<String, Object> req) {
        SopAuthPlatform authPlatform;
        authPlatform = uniClientTool.findAuthPlatform(request, "");
        req.put("realmId", authPlatform.getRealmId());
        soAssetRelVisitFeign.save(authPlatform.getPlatformId(),
                authPlatform.getModelToken(), req);
    }

    @Override
    public void delete(Map<String, Object> req) {
        SopAuthPlatform authPlatform;
        authPlatform = uniClientTool.findAuthPlatform(request, "");
        req.put("realmId", authPlatform.getRealmId());
        soAssetRelVisitFeign.delete(authPlatform.getPlatformId(),
                authPlatform.getModelToken(), req);
    }

    @Override
    public void saveAssetsOfHolder(Map<String, Object> req) {
        SopAuthPlatform authPlatform;
        authPlatform = uniClientTool.findAuthPlatform(request, "");
        req.put("realmId", authPlatform.getRealmId());
        soAssetRelVisitFeign.saveAssetsOfHolder(authPlatform.getPlatformId(),
                authPlatform.getModelToken(), req);
    }

    @Override
    public void removeAssetsOfHolder(Map<String, Object> req) {
        SopAuthPlatform authPlatform;
        authPlatform = uniClientTool.findAuthPlatform(request, "");
        req.put("realmId", authPlatform.getRealmId());
        soAssetRelVisitFeign.removeAssetsOfHolder(authPlatform.getPlatformId(),
                authPlatform.getModelToken(), req);
    }

    @Override
    public void saveHoldersOfAsset(Map<String, Object> req) {
        SopAuthPlatform authPlatform;
        authPlatform = uniClientTool.findAuthPlatform(request, "");
        req.put("realmId", authPlatform.getRealmId());
        soAssetRelVisitFeign.saveHoldersOfAsset(authPlatform.getPlatformId(),
                authPlatform.getModelToken(), req);
    }

    @Override
    public void saveAttributesOfAsset(Map<String, Object> req) {
        SopAuthPlatform authPlatform;
        authPlatform = uniClientTool.findAuthPlatform(request, "");
        req.put("realmId", authPlatform.getRealmId());
        soAssetRelVisitFeign.saveAttributesOfAsset(authPlatform.getPlatformId(),
                authPlatform.getModelToken(), req);
    }

    @Override
    public void removeAttributesOfAsset(Map<String, Object> req) {
        SopAuthPlatform authPlatform;
        authPlatform = uniClientTool.findAuthPlatform(request, "");
        req.put("realmId", authPlatform.getRealmId());
        soAssetRelVisitFeign.removeAttributesOfAsset(authPlatform.getPlatformId(),
                authPlatform.getModelToken(), req);
    }
}
